package com.ls.dbpool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

/**
 * 定期检查磁盘使用率，如过大，则进行清理
 * 
 * @author liblc
 *
 */
public class DiskCleanService {
	private static Logger logger = Logger.getLogger(DiskCleanService.class);
	private ScheduledExecutorService service;
	public void start() {
		service = Executors.newScheduledThreadPool(2);
		service.scheduleWithFixedDelay(new Runnable() {

			@Override
			public void run() {
				if (DiskCleanManager.getIntance().isOverDiskTopThreshold()) {
					try {
						DiskCleanManager.getIntance().cleanDisk();
					} catch (DiskCleanException e) {
						logger.error(e);
					}
				}
			}
		}, 5, 10, TimeUnit.MINUTES);
	}
	
	public void stop(){
		if(null!=service){
			service.shutdownNow();
		}
	}
}
